from screen_shot import gran_screen_win32
import utils
import pyautogui


def JueDouChang_task(yolo):
    # 截图
    img = gran_screen_win32((0, 0, 1920, 1080))
    result = yolo(source=img)

    for i in result[0].boxes:
        if i.cls == 0:
            print("攻击")
            utils.fire()
            for i in result[0].boxes:
                if i.cls == 2:
                    for j in result[0].boxes:
                        if j.cls == 3:
                            # 向敌人方向移动
                            print(utils.get_left_or_right(utils.get_x_y(j), utils.get_x_y(i)))
                            if utils.get_left_or_right(utils.get_x_y(j), utils.get_x_y(i)) == "左":
                                pyautogui.keyDown('a')
                            elif utils.get_left_or_right(utils.get_x_y(j), utils.get_x_y(i)) == "右":
                                pyautogui.keyDown('d')

        elif i.cls == 1:  # 自动点击决斗场开始决斗
            print("开始决斗按钮")
            pyautogui.press('k')

    if len(result[0].boxes) == 0:
        pyautogui.keyUp('k')
        pyautogui.keyUp('d')
        pyautogui.keyUp('a')
        # pyautogui.press('space')
        print("结束攻击")


def fen_rao_task(yolo):
    img = gran_screen_win32((0, 0, 1920, 1080))
    result = yolo(source=img)

    print("开启丰饶之间任务")
